package com.auxgroup.hr.front.site.co.hireperson;

import java.util.List;

import javax.annotation.Resource;

import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.auxgroup.hr.front.commons.BaseRetCode;
import com.auxgroup.hr.front.commons.vo.BaseResponseVO;
import com.auxgroup.hr.front.dao.domain.PsCHireBankacct;
import com.auxgroup.hr.front.dozer.IObjectMapper;
import com.auxgroup.hr.front.service.hireperson.HireBankacctService;
import com.auxgroup.hr.front.site.co.BaseCO;

/**
 * 入职人员银行卡CO
 * @author lvliuhao
 * @version 创建时间：180526 
 */
@RestController
@RequestMapping("${auxgroup.hr.contextPath}/hireBankacct")
public class HireBankacctCO extends BaseCO {

	private static final Logger logger = LoggerFactory.getLogger(HireBankacctCO.class);

	@Autowired
	public HireBankacctService hireBankacctService;

	@Resource(name = "dozerMapper")
	protected IObjectMapper objectMapper;

	/**
	 * 获取入职人员银行卡
	 * @param hireId
	 * @return
	 */
	@GetMapping(value = "/getOne")
	public BaseResponseVO getOne(String rsHireId) {
		logger.info("getHireBankacct param= {}", rsHireId);
		if(StringUtils.isBlank(rsHireId)){
			return buildRespone(BaseRetCode.CODE_ERROR_RSHIREID_BLANK);
		}
		PsCHireBankacct hireBankacct = hireBankacctService.getHireBankacct(rsHireId);
		return buildRespone(hireBankacct);
	}
	
	/**
	 * 保存入职人员银行卡
	 * @param hireId
	 * @return
	 */
	@PostMapping(value = "/save")
	public BaseResponseVO save(PsCHireBankacct hireBankacct) {
		logger.info("saveHireBankacct param= {}", hireBankacct);
		if(StringUtils.isBlank(hireBankacct.getRsHireId())){
			return buildRespone(BaseRetCode.CODE_ERROR_RSHIREID_BLANK);
		}
		PsCHireBankacct nowBank = hireBankacctService.getHireBankacct(hireBankacct.getRsHireId());
		if(nowBank!=null){
			objectMapper.map(hireBankacct, nowBank,"notCopyNull_hireBank");
			hireBankacct = hireBankacctService.save(nowBank);
		}else{
			hireBankacct = hireBankacctService.save(hireBankacct);
		}
		if(StringUtils.isNotBlank(hireBankacct.getRsHireId())){
			return buildRespone(true);
		}
		return buildRespone(false);
		
	}
	
	/**
	 * 删除入职人员银行卡
	 * @param hireId
	 * @return
	 */
	@PostMapping(value = "/del")
	public BaseResponseVO del(String rsHireId) {
		logger.info("delHireBankacct param= {}", rsHireId);
		if(StringUtils.isBlank(rsHireId)){
			return buildRespone(BaseRetCode.CODE_ERROR_RSHIREID_BLANK);
		}
		Boolean isdel = hireBankacctService.delete(rsHireId);
		return buildRespone(isdel);
	}
	
	/**
	 * 获取全部
	 * @param rsHireId
	 * @return
	 */
	@GetMapping(value = "/getAll")
	public BaseResponseVO getAll(String rsHireId){
		logger.info("getHireBankacct param= {}", rsHireId);
		if(StringUtils.isBlank(rsHireId)){
			return buildRespone(BaseRetCode.CODE_ERROR_RSHIREID_BLANK);
		}
		List<PsCHireBankacct> list = hireBankacctService.getAll(rsHireId);
		return buildRespone(list);
	}
	
	

}
